/**
 * 
 */
package org.jinion.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author zhlmmc
 *
 */
public class StringTool {
	private static final Log log = LogFactory.getLog(StringTool.class);
	
	/**
	 * Build a String object using the given format and args.
	 * @param format
	 * @param args
	 * @return
	 */
	public static String buildString(String format, Object ... args){
		int len = args.length;
		int j = format.indexOf('?');
		int i = 0;
		while (j >= 0 && i < len) {
			format = format.replaceFirst("\\?", args[i++].toString());
			j = format.indexOf('?');
		}
		
		if (i != len || j >= 0) {
			log.warn("String format and args do not match each other.");
		}
		
		return format;
	}
	
	public static void main(String[] args){
		System.out.println(StringTool.buildString("This is ? and ?, haha!",	"hailong", "naive"));
	}
}
